/*
 * FXGL - JavaFX Game Library. The MIT License (MIT).
 * Copyright (c) AlmasB (almaslvl@gmail.com).
 * See LICENSE for details.
 */

package com.windea.study.kotlin.fxgl.sample.basics

import com.almasb.fxgl.app.*
import com.almasb.fxgl.dsl.*
import com.almasb.fxgl.time.*
import javafx.scene.input.*
import javafx.util.*

/**
 * Shows how to use timer actions.
 * Press F to pause / resume the action.
 * Press E to make the action expire.
 *
 * @author Almas Baimagambetov (AlmasB) (almaslvl@gmail.com)
 */
class TimerActionSample : GameApplication() {
	private lateinit var timerAction: TimerAction
	
	override fun initSettings(settings: GameSettings) {}
	
	override fun initGame() {
		timerAction = getGameTimer().runAtInterval(Runnable { println("Now: " + getGameTimer().now) }, Duration.seconds(0.5))
	}
	
	override fun initInput() {
		onKeyDown(KeyCode.F, "Pause Timer") {
			if(timerAction.isPaused) timerAction.resume() else timerAction.pause()
		}
		onKeyDown(KeyCode.E, "Expire Timer") {
			timerAction.expire()
		}
	}
}

fun main(args: Array<String>) {
	GameApplication.launch(TimerActionSample::class.java, args)
}

